import axios from "axios";
import { configure } from "log4js";
import { scheduleJob } from "node-schedule";
import { OPGG, opggIndex } from "./reptile";
import { createRoute } from "./route";
import { ConfigInterface, connecDB } from "./utils";
import { qiniu } from "./utils/qiniuLoad";
import Koa from 'koa'
import Router from 'koa-router'
import { time } from "console";
import fs from 'fs'
import cheerioModule from "cheerio";
export async function serve(config: ConfigInterface) {
    if (config.logger) configure(config.logger)
    const { dbName, dbUrl, access, secret, bucket, hero,hero_alis } = config
    const dbConeect = new connecDB(dbUrl, dbName)
    const qiniuLoad = new qiniu(access, secret, bucket)
    const colOPGG = await dbConeect.mongoCol<OPGG>('opgg')

    await opggIndex(hero, colOPGG, qiniuLoad,hero_alis)
    scheduleJob('* */10 * * *', async () => {
        console.error(time())
        await opggIndex(hero, colOPGG, qiniuLoad,hero_alis)
    })
    await createRoute(8088,colOPGG)
}